﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DalatCooking.Core;
public partial class Role_Header : System.Web.UI.UserControl
{
   

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (Context.User.Identity.IsAuthenticated)
        {
            Login.Visible = false;
            Welcome.Text = "Welcome " + ((CustomIdentity)Context.User.Identity).Name;

            if (((CustomPrincipal)Context.User).Roles.Count != 0)
            {
                Roles.Visible = true;
                Roles.Text = "You are assigned to the following role(s):";
                foreach (string role in ((CustomPrincipal)Context.User).Roles)
                    Roles.Text += "<br>" + role;

                if (((CustomPrincipal)Context.User).IsInRole("SuperUser"))
                    RoleManager.Visible = true;
            }
        }
        else
        {
            Account.Visible = false;
            SignOut.Visible = false;
            Welcome.Text = "Welcome, Guest";
        }
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    ///		Required method for Designer support - do not modify
    ///		the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.SignOut.Click += new System.EventHandler(this.SignOut_Click);
        this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

    private void SignOut_Click(object sender, System.EventArgs e)
    {
        System.Web.Security.FormsAuthentication.SignOut();
        Response.Redirect("Default.aspx");
    }
}